<template>
  <div>
    <el-form ref="cusForm" :model="dataForm" label-width="120px" size="small" :rules="rules">
      <el-row>
        <el-col :span="24">
          <el-form-item label="分行名称：" prop="organizationName" label-width="150px">
            <el-input  placeholder="" v-model="dataForm.organizationName"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <el-form-item label="分行机构编码：" prop="organizationCode" label-width="150px">
            <el-input  placeholder="" v-model="dataForm.organizationCode"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <el-form-item label="下属客户经理：" label-width="150px">
            <ul class="tag-list" @click="addUserEvent">
              <li class="tag-item" v-for="(item, index) in listValue" :key="index">{{item.managerName}}({{item.managerNo}})</li>
            </ul>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <el-row>
      <el-col :span="24" :offset="10">
        <el-button type="" @click="close">取消</el-button>
        <el-button type="primary" @click="submit">确定</el-button>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import { mapState } from 'vuex'
export default {
  props: {
    listValue: Array,
    editData: Object
  },
  data () {
    return {
      dataForm: {
        organizationCode: '',
        organizationName: ''
      },
      rules: {
        organizationName: [{ required: true, message: '请输入分行名称', trigger: 'blur' }],
        organizationCode: [{ required: true, message: '请输入机构编码', trigger: 'blur' }]
      }
    }
  },
  mounted () {
    if (this.editData && this.editData.organizationId) {
      this.dataForm = {...this.editData}
      console.log(this.listValue)
    }
  },
  methods: {
    addUserEvent () {
      this.$emit('showAddUser')
    },
    close () {
      this.$emit('close')
    },
    submit () {
      this.$refs['cusForm'].validate((valid) => {
        if (valid) {
          if (this.listValue.length === 0) {
            this.$message({
              message: '请至少添加一名客户经理',
              type: 'warning'
            })
            return false
          }
          this.$emit('updataSuccess', this.dataForm)
        }
      })
    }
  },
  computed: {
    ...mapState({
      dicts: state => state.common.dicts
    })
  }
}
</script>
<style lang="less">
.tag-list{
  width: 90%;
  min-height: 40px;
  border-radius: 4px;
  border: 1px solid #DCDFE6;
  list-style: none;
  display: flex;
  justify-content: flex-start;
  align-items: center;
  flex-wrap: wrap;
  box-sizing: border-box;
  padding: 5px 0;
  margin-bottom: 10px;
  cursor: pointer;
  .tag-item{
    display: inline-block;
    box-sizing: border-box;
    padding: 2px 10px;
    font-size: 12px;
    border: 1px solid #DCDFE6;
    margin: 0 5px 5px 5px;
    line-height: 22px;
    border-radius: 4px;
  }
}
</style>
